//
//  RecStoryDetailsTableViewCell.m
//  TravelEveryDay
//
//  Created by dlios on 15-10-19.
//  Copyright (c) 2015年 com.lanou3g. All rights reserved.
//

#import "RecStoryDetailsTableViewCell.h"

@implementation RecStoryDetailsTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _image = [[UIImageView alloc] initWithFrame:CGRectZero];
        
        [self.contentView addSubview:_image];
        
        _label = [[UILabel alloc] initWithFrame:CGRectZero];
      
        _label.font = [UIFont systemFontOfSize:16.];
        [_label setNumberOfLines:0];
        [self.contentView addSubview:_label];
    }
    return  self;
}
-(void)getStoryData:(RecStoryDetailsModel *)model
{
    [_image sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:PLACEHOLDERIMAGE];
    _label.text = model.text;
    
    if ([model.photo_width.stringValue isEqualToString:@""]|| [model.photo_height.stringValue isEqualToString:@""]) {
        _imageHeight = 0;
    }else{
       
        _imageHeight = 250 * WIDTH * model.photo_height.integerValue / model.photo_width.integerValue;
        _image.frame = CGRectMake(10 * WIDTH, 0, SCREEN_WIDTH - 20 * WIDTH, _imageHeight);
    }
    if (![model.text isEqualToString:@""]) {
        
        _textHeight = [StringWithHeight heightWithText:_label.text width:SCREEN_WIDTH - 20 * WIDTH font:[UIFont systemFontOfSize:16.]];
        _label.frame = CGRectMake(10 * WIDTH, _imageHeight + 20 * HEIGHT, SCREEN_WIDTH - 20 * WIDTH, _textHeight);
    }else{
        _label.frame = CGRectZero;
    }

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
